package com.dce.dev.api.controller.basebusiness;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.dce.dev.api.common.tools.JsonFileTool;
import com.dce.dev.api.common.tools.json.JsonUtils;
import com.dce.dev.api.dto.base.ResultDTO;
import com.dce.dev.api.dto.basebusiness.appuser.LoginReqDTO;
import com.dce.dev.api.dto.basebusiness.appuser.LoginResDTO;
import com.dce.dev.api.dto.basebusiness.appuser.RegisterDTO;
import com.dce.dev.api.dto.basebusiness.appuser.RegisterReqDTO;
import com.dce.dev.api.dto.basebusiness.appuser.ResetpasswordReqDTO;
import com.dce.dev.api.dto.basebusiness.appuser.RoleResDTO;
import com.dce.dev.api.dto.basebusiness.appuser.UserProfileResDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;


/**
 * 基础接口
 */
@RestController
@RequestMapping("/appuser")
@Api(value = "后台服务--APP基础功能", description = "后台服务--APP基础功能")
public class AppUserController {
	
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    @ApiOperation(value = "登录认证")
    public ResultDTO<LoginResDTO> login(@RequestBody LoginReqDTO dtoReq) {
        String strProfileJson = JsonFileTool.readJSON("basebusiness/appuser/profile.json");
        final UserProfileResDTO userProfileReqDTO = JsonUtils.jsonToPojo(strProfileJson, UserProfileResDTO.class);
        String strRoleJson = JsonFileTool.readJSON("basebusiness/appuser/role.json");
        final RoleResDTO roleReqDTO = JsonUtils.jsonToPojo(strRoleJson, RoleResDTO.class);
        
        LoginResDTO loginResDTO=new LoginResDTO();
        loginResDTO.setAccessToken("3b1edbd9b-3dfdjkd-sdfjkjsd-dfjkd-23dfd");
        List<String> permissionsList=new ArrayList<String>();
        permissionsList.add("delivery:menu");
        permissionsList.add("dept:create");
        permissionsList.add("menu:read");
        loginResDTO.setPermissions(permissionsList);
        loginResDTO.setProfile(userProfileReqDTO);
        List<RoleResDTO> roleList=new ArrayList<RoleResDTO>();
        roleList.add(roleReqDTO);
        loginResDTO.setRoles(roleList);
        
        return ResultDTO.success(loginResDTO,"登录成功");
    }
    
    
    @RequestMapping(value = "/loginout", method = RequestMethod.POST)
    @ApiOperation(value = "注销登录")
    public ResultDTO<Void> logout() {
    	return ResultDTO.success("注销成功");
    }
   
    
}
